import React, { Component, Fragment } from 'react';
import { connect } from 'dva';
import { Spin } from 'antd';
import EditPage from '@/components/EditPage';
import DetailPage from '@/components/DetailPage';
import { formItemFragement, queryDict, queryPerson,formatPrice } from '@/utils/common';
import { allDictList } from '@/utils/constans';
import {
  selectArchivesDetailAndInfo,
  renderTableAdSelect,
  emptyTypeList,
  allUrl,
  allDispatchType,
  archivesStatusList,
} from './utils';
import ArchivesDriverslInfo from './ArchivesDriverslInfo';

@connect(({ Archives, loading, component }) => ({
  Archives,
  emptyDetails: Archives.emptyDetails,
  dictObject: component.dictObject,
  loading: loading.effects[allDispatchType.selectEmptyDetails],
}))
export default class ArchivesDetailEmpty extends Component {
  state = {
    detail: {},
  };
  componentWillMount() {
    // 查询字典项
    const allDict = [
      allDictList.cabinetTypeHK,
      allDictList.emptyType,
      allDictList.emptyType_ZG,
      allDictList.emptyType_QS,
      allDictList.driverType,
    ];
    queryDict({ props: this.props, allDict });
  }

  componentDidMount() {
    const { detailId } = this.props;
    if (detailId) this.getEmptyDetails();
  }
  getEmptyDetails = () => {
    const { dispatch, detailId } = this.props;
    dispatch({
      type: allDispatchType.selectEmptyDetails,
      payload: { id: detailId },
    });
  };

  handleStateChange = (options = []) => {
    options.map(item => {
      this.setState(item);
    });
  };

  render() {
    const { loading, emptyDetails, detailId, businessType ,dictObject} = this.props;
    const detail = emptyDetails[detailId] || {};
    // console.log('detail==========',detail.emptyType,dictObject[allDictList.emptyType],dictObject[allDictList.emptyType_ZG])
    const editPageParams = {
      panelValue: [
        { key: '基础信息' },
        detail.status !== 'UNSEALED' && {
          key: '司机提成',
        },
      ],
    };

    const formItem = [
      [
        <DetailPage
          label="司机类型"
          value={renderTableAdSelect({
            value: detail.driverType,
            // data: allDictList.emptyType, 
            data:dictObject[allDictList.driverType]
          })}
        />,
        
      ],
      [
        <DetailPage
          label="异常类型"
          value={renderTableAdSelect({
            value: detail.emptyType,
            // data: allDictList.emptyType, 
            data:
            detail.driverType?
            (detail.driverType=='HW01' ?dictObject[allDictList.emptyType_ZG]:dictObject[allDictList.emptyType_QS])
            :dictObject[allDictList.emptyType]
            
          })}
        />,
        <DetailPage
          label="异常金额"
          value={formatPrice(detail.abnormalAmount)}
        />,
      ],
      [
        <DetailPage label="司机" value={detail.driverName} />,
        <DetailPage
          label="状态"
          value={renderTableAdSelect({
            props: this.props,
            value: detail.status,
            data: archivesStatusList,
          })}
        />,
      ],
      [
        <DetailPage label="结算周期" value={detail.settlementDate} />,
        <DetailPage label="关联车次号" value={detail.mergeTrainNo} />,
      ],
      [<DetailPage label="备注" value={detail.remark} />,
       <DetailPage label="发车日期" value={detail.transportStartTime} />,
      ],
    ];

    return (
      <EditPage {...editPageParams}>
        <Spin spinning={loading}>{formItemFragement(formItem)}</Spin>
        {detail.status !== 'UNSEALED' && (
          <Fragment>
            <ArchivesDriverslInfo businessType={businessType} archivesId={detailId} isHK={true} />
          </Fragment>
        )}
      </EditPage>
    );
  }
}
